home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / prog / asmlib35.zip / ASM3DEMO.ZIP / STARTUP.ASM < prev    next >
Assembly Source File  |  1992-10-02  |  2KB  |  108 lines

  1. include    asm.inc
  2.  
  3. extrn    endprog:proc
  4. extrn    breaktrap:proc
  5. extrn    breakrelease:proc
  6. IFDEF    HEAP
  7. extrn    hinit:proc
  8. ENDIF
  9. extrn    mymain:proc
  10.  
  11. ; make LINK search through ASMLIB for external references
  12. ; so I don't have to specify ASMLIB on the command line
  13. IF codesize EQ 1
  14. IF datasize EQ 2
  15.     IFDEF    NOXT
  16.     includelib    asmhuge.286
  17.     ELSE
  18.     includelib    asmhuge
  19.     ENDIF
  20. ELSE
  21.     IFDEF    NOXT
  22.     includelib    asmlib.286
  23.     ELSE
  24.     includelib    asmlib
  25.     ENDIF
  26. ENDIF
  27. ELSE
  28.     IFDEF    NOXT
  29.     includelib    asmsmall.286
  30.     ELSE
  31.     includelib    asmsmall
  32.     ENDIF
  33. ENDIF
  34.  
  35. stacksize    equ    1024
  36.  
  37. .stack stacksize
  38.  
  39. .data
  40. public    pspseg
  41. pspseg        dw    ?        ; storage for PSP segment
  42.  
  43. IFDEF    HEAP
  44. ; make some space available for the local heap
  45. heapsize    equ    32767
  46. heapbuffer    db    heapsize dup(0)
  47. ENDIF
  48.  
  49. .code
  50. start:
  51. ; start by pointing DS to DGROUP
  52.     mov    dx,@data
  53.     mov    ds,dx
  54.     assume    ds:@data
  55.  
  56.     mov    ax,ss
  57.     sub    ax,dx
  58.     mov    cl,4
  59.     shl    ax,cl
  60.     add    sp,ax
  61.     mov    ss,dx
  62.  
  63. ; save PSP segment for DOS 2.xx
  64.     mov    pspseg,es
  65.  
  66. ; next, release memory beyond the end of the program
  67. ; The file ENDPROG.ASM has a definition for ZSEG, marking the
  68. ; end of the program's code, data and stack area.  I want to
  69. ; release memory beyond ZSEG so I can use DOS function 48h for
  70. ; memory allocation.
  71. ; When linking ENDPROG.OBJ with your other object files, be sure
  72. ; ENDPROG is at the end of your list of object files.  The new segment
  73. ; ZSEG surprises link, and it has little choice but to put ZSEG
  74. ; at the end of the program.
  75.     call    endprog            ; returns AX = last segment 
  76.  
  77.     mov    bx,es            ; first segment (ES = seg PSP)
  78.     sub    bx,ax
  79.     neg    bx            ; size of program in paragraphs
  80.     mov    ah,4Ah            ; resize memory block
  81.     int    21h
  82.  
  83. IFDEF    HEAP
  84. ; need to initialize the heap in order to work properly.  A common cause
  85. ; of bombed programs is failure to initilaize the heap.
  86.     lea    bx,heapbuffer
  87.     mov    ax,heapsize
  88.     call    hinit
  89. ENDIF
  90.  
  91. ; prevent an unintended program crash; trap Ctrl+Break, Ctrl+C and
  92. ; Ctrl+Alt+Del key combinations
  93.     call    breaktrap
  94.  
  95. ; call your main program here
  96.     call    mymain
  97.  
  98. exit:
  99. ; de-activate the Ctrl+Break trap
  100.     call    breakrelease
  101.  
  102. ; normal program exit
  103.     mov    ax,4C00h
  104.     int    21h
  105.  
  106. end    start
  107.     end
  108.